package com.sls.game.dao.wogreat.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.wogreat.WogreatDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.wogreat.WogreatProduct;

@Repository("wogreatDAO")
public class WogreatDAOImpl extends SuperDAO<WogreatProduct> implements
		WogreatDAO {

	@Override
	public void insertProduct(WogreatProduct product) {
		this.getSqlSession().insert("mybatis.xml.WogreatProductMapper.insert",
				product);

	}

	@Override
	public void update(WogreatProduct product) {
		this.getSqlSession().update("mybatis.xml.WogreatProductMapper.update",
				product);

	}

	@Override
	public WogreatProduct queryById(String id) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.WogreatProductMapper.selectByPrimaryKey", id);
	}

	@Override
	public Pagination<WogreatProduct> queryPage(WogreatProduct product) {
		Pagination<WogreatProduct> paginationList = null;
		Integer rowCount = queryRowCount(product);

		product.calculate();
		List<WogreatProduct> list = queryGoodsInfoList(product);
		paginationList = this.queryPagination(rowCount, list, product);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(WogreatProduct product) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.WogreatProductMapper.queryRowCount", product);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<WogreatProduct> queryGoodsInfoList(WogreatProduct product) {
		List<WogreatProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.WogreatProductMapper.queryWogreatProductInfoList",
				product);
		return list;
	}

	@Override
	public WogreatProduct queryByProId(String proId) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.WogreatProductMapper.queryByProId", proId);
	}

	@Override
	public List<WogreatProduct> queryAllWoInfo(WogreatProduct product) {
		List<WogreatProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.WogreatProductMapper.queryAllWoInfo", product);
		return list;
	}

}
